package com.my.system.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BCryptUtils {
    /**
     * 对密码进行加密
     * @param password
     * @return
     */
    public static String encryptPassword(String password){
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.encode(password);

    }

    /**
     * 验证密码是否正确
     * @param inputPassword  用户输入的密码
     * @param encryptPassword  从数据库查的密码
     * @return
     */
    public static boolean matchesPassword(String inputPassword,String encryptPassword){
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.matches(inputPassword,encryptPassword);
    }
}
